package zli.prototype.shallow;


import java.util.ArrayList;
import java.util.List;

/**
 * @Desc
 * @Author Zerlinda
 * @Date 2022/5/9 10:33
 * @Version 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 创建原型对象
        ConcretePrototype concretePrototype = new ConcretePrototype();
        List<String> hobbies = new ArrayList<>();
        hobbies.add("音乐");
        hobbies.add("美术");
        concretePrototype.setAge(14);
        concretePrototype.setName("Tom");
        concretePrototype.setHobbies(hobbies);
        System.out.println(concretePrototype);

        // 拷贝原型对象
        ConcretePrototype cloneType = concretePrototype.clone();
        hobbies.add("技术控");

        System.out.println("原型对象：" + concretePrototype);
        System.out.println("克隆对象：" + cloneType);
        // 原型对象和克隆对象是不同的地址
        System.out.println(concretePrototype == cloneType);
        // 原型对象和克隆对象中的List是相同的地址
        System.out.println(concretePrototype.getHobbies() == cloneType.getHobbies());


    }
}
